package com.ruoyi.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.result.Result;
import com.ruoyi.domain.T01;
import com.ruoyi.domain.T06;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.service.IT01Service;
import com.ruoyi.service.IT06Service;
import com.ruoyi.service.IT10Service;
import com.ruoyi.uitity.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.T12Mapper;
import com.ruoyi.domain.T12;
import com.ruoyi.service.IT12Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 信息反馈Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-27
 */
@Service
public class T12ServiceImpl implements IT12Service
{
    @Autowired
    private T12Mapper t12Mapper;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IT06Service t06Service;
    @Autowired
    private IT01Service t01Service;



    /**
     * 查询信息反馈
     *
     * @param F1201 信息反馈主键
     * @return 信息反馈
     */
    @Override
    public T12 selectT12ByF1201(Long F1201)
    {
        return t12Mapper.selectT12ByF1201(F1201);
    }

    /**
     * 查询信息反馈列表
     *
     * @param t12 信息反馈
     * @return 信息反馈
     */
    @Override
    public List<T12> selectT12List(T12 t12)
    {
        return t12Mapper.selectT12List(t12);
    }

    /**
     * 新增信息反馈
     *
     * @param t12 信息反馈
     * @return 结果
     */
    @Override
    public int insertT12(T12 t12)
    {
        return t12Mapper.insertT12(t12);
    }

    /**
     * 修改信息反馈
     *
     * @param t12 信息反馈
     * @return 结果
     */
    @Override
    public int updateT12(T12 t12)
    {
        return t12Mapper.updateT12(t12);
    }

    /**
     * 批量删除信息反馈
     *
     * @param F1201s 需要删除的信息反馈主键
     * @return 结果
     */
    @Override
    public int deleteT12ByF1201s(Long[] F1201s)
    {
        return t12Mapper.deleteT12ByF1201s(F1201s);
    }

    /**
     * 删除信息反馈信息
     *
     * @param F1201 信息反馈主键
     * @return 结果
     */
    @Override
    public int deleteT12ByF1201(Long F1201)
    {
        return t12Mapper.deleteT12ByF1201(F1201);
    }

    @Override
    public Result addT12(T12 t12, HttpServletRequest request) {
        Long userId = tokenService.getLoginUser(request).getUserId();
        T06 t06 = t06Service.selectT06ByF0601(userId);
        t12.setF0601(t06.getF0601());
        t12.setF0301(t06.getF0301());
        t12.setF1202(t06.getF0602());
        t12.setF1208(t06.getF0618());
        t12.setF1204(new Date());
        t12.setF1205(1L);
        t12Mapper.insertT12(t12);
        return Result.success();
    }

    @Override
    public Result toProcess(T12 t12, HttpServletRequest request) {
        Long userId = tokenService.getLoginUser(request).getUserId();
        T01 t01 = t01Service.selectT01ByF0101(userId);
        t12.setF0101(userId);
        t12.setF1210(t01.getF0103());
        t12.setF1206(new Date());
        t12.setF1205(0L);
        t12Mapper.updateT12(t12);
//        MailUtil.sendMail(t12.getF1209(),"反馈回复","反馈回复："+t12.getF1207());
        return Result.success();
    }

    @Override
    public Result testEmail(HttpServletRequest request) {
        MailUtil.sendMail("17765573875@163.com","测试邮件","测试邮件");
        return Result.success();
    }

    @Override
    public Result getWxList(T12 t12, HttpServletRequest request) {
        Long userId = tokenService.getLoginUser(request).getUserId();
        T06 t06 = t06Service.selectT06ByF0601(userId);
        t12.setF0601(t06.getF0601());
        List<T12> t12s = t12Mapper.selectT12List(t12);
        return Result.success(t12s,"查询成功");
    }
}
